package com.hooker.plugins;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;

import com.hooker.base.BaseXposedLoader;

import java.util.Arrays;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class ResoucesEntry  extends BaseXposedLoader {

    public ResoucesEntry(Context context, XC_LoadPackage.LoadPackageParam loadParams) {
        super(context, loadParams);
    }

    @Override
    public void hook(Object... calls) {
        log("hook~~");
        hookAllMethod(Resources.class, "loadDrawable", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                log("loadDeawable this:"+param.thisObject+" args:"+ Arrays.toString(param.args));
                int i = (int)param.args[1];
                if(i == 0x7f0c0079){
                    Resources thisObject = (Resources) param.thisObject;
                    AssetManager assets = thisObject.getAssets();

                    log(" this :"+param.thisObject);
                    log(" assets :"+assets);
                    log("assets.list:"+Arrays.toString(assets.list("/")));
                }
                super.afterHookedMethod(param);
            }
        });

        hookMethod(Resources.class, "newTheme", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                log("newTheme:"+param.getResult());
            }
        });
    }
}
